package com.bz.sunmipay.adapter;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.baizhi.baseapp.adapter.BasePageAdapter;
import com.bz.sunmipay.R;
import com.bz.sunmipay.model.HomeInfo;
import com.bz.sunmipay.utils.AppUtils;

/**
 * 首页
 * <p>
 * Created by liuyakui on 2019-09-07.
 */
public class HomeInfoAdapter extends BasePageAdapter<HomeInfo> {

    public HomeInfoAdapter(Context ctx) {
        super(ctx);
    }

    @Override
    protected int getResource(int position) {
        return R.layout.home_item;
    }

    @Override
    protected void renderConvertView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = (ViewHolder) convertView.getTag();
        if (holder == null) {
            holder = new ViewHolder(convertView);
        }
        HomeInfo item = getItem(position);
        holder.name.setText(item.name);

        if (!TextUtils.isEmpty(item.icon)) {
            convertView.setBackgroundResource(R.drawable.bg_homeicon_selector);
        } else {
            convertView.setBackground(new ColorDrawable(mContext.getResources().getColor(R.color.white)));
        }
        holder.homeLogo.setImageDrawable(AppUtils.getDrawable(mContext, item.icon));
    }

    private class ViewHolder {
        TextView name;
        ImageView homeLogo;

        ViewHolder(View view) {
            name = view.findViewById(R.id.name);
            homeLogo = view.findViewById(R.id.home_logo);
        }
    }
}
